//
//  QYGAccountCell.m
//  wawaji_ios
//
//  Created by 云+物娱 on 2017/12/1.
//  Copyright © 2017年 yiguo qi. All rights reserved.
//

#import "QYGAccountCell.h"

@interface QYGAccountHeader()

@property (nonatomic, strong) UILabel *detailLabel;
@property (nonatomic, strong) UILabel *accountLabel;
@property (nonatomic, strong) UIButton *goRechargeBtn;

@end

@implementation QYGAccountHeader

- (void)setDetailStr:(NSString *)detailStr{
    
    _detailStr = detailStr;
    self.detailLabel.text = detailStr;
    [self.detailLabel sizeToFit];
}
- (void)setNameStr:(NSString *)nameStr{
    _nameStr = nameStr;
    self.accountLabel.text = nameStr;
    [self.accountLabel sizeToFit];
    
}

- (void)accountHeaderWithNameStr:(NSString *)nameStr detailStr:(NSString *)detailStr{
    _nameStr = nameStr;
    _detailStr = detailStr;
    
    self.detailLabel.text = detailStr;
    self.accountLabel.text = nameStr;
    [self.detailLabel sizeToFit];
    [self.accountLabel sizeToFit];
}

- (void)goRechargeBtnClick{
    if(self.accountHeaderRechargeBlock){
        self.accountHeaderRechargeBlock();
    }
}
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        
        self.backgroundColor = [UIColor whiteColor];
        [self initUI];
    }
    return self;
}
- (void)initUI{
    
    [self addSubview:self.detailLabel];
    [self addSubview:self.accountLabel];
    [self addSubview:self.goRechargeBtn];
    [self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(ScaleH(20));
        make.centerX.equalTo(self.mas_centerX);
    }];
    
    [self.accountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.detailLabel.mas_centerX);
        make.top.equalTo(self.detailLabel.mas_bottom).offset(ScaleH(12));
    }];
    
    [self.goRechargeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-ScaleW(15));
        make.centerY.equalTo(self.mas_centerY);
    }];
}
- (void)setFrame:(CGRect)frame{
    frame.size.height -= 1;
    [super setFrame:frame];
}
- (UILabel *)detailLabel{
    
    if(!_detailLabel){
        _detailLabel = [UILabel labelWithText:@"金币余额" setFont:ScaleBoldFont(13) setTextColor:[UIColor colorWithHex:@"999999"] setTextAlignment :NSTextAlignmentCenter];
        [_detailLabel sizeToFit];
    }
    return _detailLabel;
}

- (UILabel *)accountLabel{
    
    if(!_accountLabel){
        _accountLabel = [UILabel labelWithText:@"0币" setFont:ScaleBoldFont(30) setTextColor:[UIColor colorWithHex:@"ffb52b"] setTextAlignment :NSTextAlignmentCenter];
    }
    return _accountLabel;
}

- (UIButton *)goRechargeBtn{
    if(!_goRechargeBtn){
        _goRechargeBtn = [UIButton buttonWithTitle:@"去充值 >" setTitleColor:[UIColor colorWithHex:@"09bb07"] setTitleFont:ScaleFont(12) setState:UIControlStateNormal];
        [_goRechargeBtn sizeToFit];
        [_goRechargeBtn addTarget:self action:@selector(goRechargeBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _goRechargeBtn;
}
@end
@interface QYGAccountCell()

@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *detailLabel;
@property (nonatomic, strong) UILabel *accessoryLabel;
@property (nonatomic, strong) UIView *lineView;

@end

@implementation QYGAccountCell

- (void)accountCellWithNameStr:(NSString *)nameStr detailStr:(NSString *)detalStr accessoryStr:(NSString *)accessoryStr accessoryColor:(UIColor *)accessoryColor{
    
    _nameStr = nameStr;
    _detailStr = detalStr;
    _accessoryStr = accessoryStr;
    
    self.nameLabel.text = nameStr;
    self.detailLabel.text = detalStr;
    self.accessoryLabel.text = accessoryStr;
    self.accessoryLabel.textColor = accessoryColor;
    
    [self.nameLabel sizeToFit];
    [self.detailLabel sizeToFit];
    [self.accessoryLabel sizeToFit];
}
- (void)setAccessoryStr:(NSString *)accessoryStr{
    
    _accessoryStr = accessoryStr;
    self.accessoryLabel.text = accessoryStr;
    [self.accessoryLabel sizeToFit];
}
- (void)setDetailStr:(NSString *)detailStr{
    
    _detailStr = detailStr;
    self.detailLabel.text = detailStr;
    [self.detailLabel sizeToFit];
}
- (void)setNameStr:(NSString *)nameStr{
    _nameStr = nameStr;
    self.nameLabel.text = nameStr;
    [self.nameLabel sizeToFit];

}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        
        [self initUI];
    }
    return self;
}
- (void)initUI{
    
    [self addSubview:self.nameLabel];
    [self addSubview:self.detailLabel];
    [self addSubview:self.accessoryLabel];
    [self addSubview:self.lineView];
    
    [self.accessoryLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-ScaleW(15));
        make.centerY.equalTo(self.mas_centerY);
    }];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.nameLabel.x = ScaleW(15);
    self.nameLabel.y = ScaleH(12);
    
    self.detailLabel.x = self.nameLabel.x;
    self.detailLabel.y = CGRectGetMaxY(self.nameLabel.frame) + ScaleH(8);
    
    self.lineView.x = self.nameLabel.x;
    self.lineView.width = self.width - 2 *self.lineView.x;
    self.lineView.height = 1;
    self.lineView.y = self.height - self.lineView.height;
    
}

#pragma mark lazy
- (UILabel *)accessoryLabel{
    
    if(!_accessoryLabel){
        _accessoryLabel = [UILabel labelWithFont:ScaleBoldFont(16) setTextColor:[UIColor colorWithHex:@"ffb52b"] setTextAlignment:NSTextAlignmentRight];
        _accessoryLabel.numberOfLines = 1;
    }
    return _accessoryLabel;
}

- (UILabel *)detailLabel{
    
    if(!_detailLabel){
        _detailLabel = [UILabel labelWithText:@"" setFont:ScaleFont(12) setTextColor:[UIColor colorWithHex:@"999999"] setTextAlignment :NSTextAlignmentLeft];
        _detailLabel.numberOfLines = 1;
    }
    return _detailLabel;
}
- (UILabel *)nameLabel {
    
    if(!_nameLabel){
        
        _nameLabel = [UILabel labelWithText:@"" setFont:ScaleFont(14) setTextColor:[UIColor colorWithHex:@"333333"] setTextAlignment :NSTextAlignmentLeft];
        _nameLabel.numberOfLines = 1;
    }
    return _nameLabel;
}
- (UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor colorWithHex:@"e1e4eb"];
    }
    return _lineView;
}
@end
